function saveData() {
	var form = baseJs.getForm("addForm");
	if (!form.isVal()) {
		alert("请按要求填写数据！");
		return;
	}
	var json = form.getItems();
	json["pageType"] = baseJs.request("pageType");
	$.post(host + "moduleAction/saveField.html", json, function(data) {
		if (data.status == "ok") {
			baseJs.getOpenWindow().alert(data.msg);
			baseJs.getOpenWindow().fieldDataGrid.datagrid('reload');
			baseJs.getOpenWindow().dialog.close();
		} else {
			alert(data.msg);
		}
	}, "json");
}
var hiddenFieldDivs = {
	list: ['treeTypeDiv', 'optionsDiv', 'defaultValueDiv', 'isNotUpdateDiv'],
	tree: ['isOperationDiv', 'isNotNullDiv', 'defaultValueDiv', 'isNotUpdateDiv', 'orderByDescDiv', 
			'widthDiv', 'heightDiv', 'formatDiv', 'optionsDiv', 'orderByDiv', 'isHideDiv'],
	edit: ['isOperationDiv', 'treeTypeDiv', 'orderByDescDiv']
};
var pageData = {};
$(function() {
	var id = baseJs.request("id");
	if (id) {
		$("#id").val(id);
		$("#tableName").text(baseJs.request("tableName"));
		$.post(host + "moduleAction/getModuleFieldById.html", {id: id}, function(data) {
			if (data.status == "error") {
				alert(data.msg);
			} else {
				data = data.data;
				for (var key in data) {
					$("#" + key).val(data[key]);
				}
				pageData = data;
				setIsId(data.isId);
			}
		}, "json");
	}
	if (baseJs.request("pageType") == "tree") {
		$("#isOperation").val("0");
		$("#isNotNull").val("0");
		$("#defaultValue").val("");
		$("#isNotUpdate").val("0");
		
		for (var i = 0;i < hiddenFieldDivs['tree'].length;i ++) {
			$("#" + hiddenFieldDivs['tree'][i]).hide();
		}
	} else if (baseJs.request("pageType") == "list") {
		$("#isNotNull").val("0");
		$("#defaultValue").val("");
		$("#isNotUpdate").val("0");
		
		for (var i = 0;i < hiddenFieldDivs['list'].length;i ++) {
			$("#" + hiddenFieldDivs['list'][i]).hide();
		}
	} else if (baseJs.request("pageType") == "edit") {
		$("#isOperation").val("0");
		
		for (var i = 0;i < hiddenFieldDivs['edit'].length;i ++) {
			$("#" + hiddenFieldDivs['edit'][i]).hide();
		}
	}
});
function changeType(value) {
	$("#fixed").attr("disabled", value != "float");
}
function setIsId(value) {
	if (value == "1") {
		$("#isNotNull").val("0");
		$("#isNotNull").attr("disabled", true);
		$("#isHide").val("1");
		$("#isHide").attr("disabled", true);
		$("#isNotUpdate").val("1");
		$("#isNotUpdate").attr("disabled", true);
	} else {
		$("#isNotNull").val(pageData.isNotNull != undefined ? pageData.isNotNull : "0");
		$("#isHide").val(pageData.isHide != undefined ? pageData.isHide : "0");
		$("#isNotUpdate").val(pageData.isNotUpdate != undefined ? pageData.isNotUpdate : "0");
		
		$("#isNotNull").attr("disabled", false);
		$("#isHide").attr("disabled", false);
		$("#isNotUpdate").attr("disabled", false);
	}
}
function closeWin() {
	baseJs.getOpenWindow().dialog.close();
}